package com.wf.messageBoard.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wf.apicommons.entity.MessageBoard.LeavingAMessage;
import com.wf.apicommons.entity.articleManagement.ArticleDetails;
import com.wf.apicommons.entity.MessageBoard.MqMessage;
import com.wf.apicommons.utils.CommonResult;
import com.wf.messageBoard.service.local.MessageBoardService;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/messageBoard")
public class MessageBoardController {

    @Autowired
    @Qualifier("messageBoardServiceImpl")
    MessageBoardService mbs;


    /**
     * 推送博客数据到RabbitMQ,实现同步ES数据
     * @param data
     * @return
     */
    @PostMapping(value = "/pushBlog")
    public CommonResult<String> pushBlogData(@RequestBody MqMessage<ArticleDetails> data) {
        return mbs.pushBlogDataService(data);
    }

    /**
     * 推送留言数据到MQ
     * @param data
     * @return
     */
    @PostMapping(value = "/pushLeavingAMessage")
    public  CommonResult<String> pushLeavingAMessageData(@RequestBody MqMessage<LeavingAMessage> data){
        return mbs.pushLeavingAMessageDataService(data);
    }


    /**
     * 查询留言消息未读数量

     * @return
     */
    @GetMapping(value = "/queryUnreadQuantity/{userId}")
    public CommonResult<List<Map<String,Object>>> queryLeavingAMessageUnreadQuantity(@PathVariable("userId") String userId){
        return mbs.queryLeavingAMessageUnreadQuantity(userId);
    }


    /**
     * 修改留言消息读取状态
     * @param param
     * @return
     */
    @PostMapping(value = "/updateReadStatus")
    public CommonResult<String> updateLeavingAMessageReadStatus(@RequestBody Map<String,Object> param){
        return mbs.updateLeavingAMessageReadStatus(param);
    }

    /**
     * 查询留言列表
     * @param param
     * @return
     */
    @PostMapping(value = "/queryList")
    public CommonResult<Page<Map<String,Object>>> queryLeavingAMessageList(@RequestBody  Map<String,Object> param){
        return mbs.queryLeavingAMessageList(param);
    }

    /**
     * 处理好友验证消息
     * @param param
     * @return
     */
    @PostMapping(value = "/processFriend")
    public CommonResult<String>  processFriendApplication(@RequestBody  Map<String,Object> param){
        return mbs.processFriendApplication(param);
    }

}
